# -*- coding: utf-8 -*
from os import path
from app import app
import sqlite3
import os
from flask_apscheduler import APScheduler
import db
#import dht11_example
from mail import send_mail
scheduler = APScheduler()
def task(a,b):
    db.deleteData()
    print (b)

if __name__ == "__main__":
    db.createDatabase()
    db.insertData()
    send_mail()
    scheduler.init_app(app=app)
    scheduler.add_job(func=task, id='1', args=(1, 'scheduler run successful'),
                      trigger='interval', days=5, replace_existing=True)
    scheduler.start()

    extra_dirs = ['app/static', ]
    extra_files = extra_dirs[:]
    for extra_dir in extra_dirs:
        for dirname, dirs, files in os.walk(extra_dir):
            for filename in files:
                filename = path.join(dirname, filename)
                if path.isfile(filename):
                    extra_files.append(filename)

    app.run(debug=True, extra_files=extra_files)


